package com.mbg17.service.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author LuYuan
 * @version 1.0
 * @date 2021/8/28 9:12 下午
 * @File : MyMetaObjectHandler.java
 * @Describe: IntelliJ IDEA
 */
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        Date date = new Date();
        this.strictInsertFill(metaObject, "createBy", String.class, "root");
        this.strictInsertFill(metaObject, "createTime", Date.class, date);
        this.strictInsertFill(metaObject, "updateBy", String.class, "root");
        this.strictInsertFill(metaObject, "updateTime", Date.class, date);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject, "updateBy", String.class, "root");
        this.strictUpdateFill(metaObject, "updateTime", Date.class, new Date());
    }
}
